package com.xiaohao.server.parkmap.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaohao.server.parkmap.entity.ShopItem;
import com.xiaohao.server.parkmap.mapper.ShopItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;

@Service
public class ShopItemService {
    @Autowired
    private ShopItemMapper shopItemMapper;

    public ShopItem queryById(Integer id) {
        return shopItemMapper.selectById(id);
    }

    public ShopItem queryOne(ShopItem shopItem) {
        return shopItemMapper.selectOne(new QueryWrapper<>(shopItem));
    }

    public List<ShopItem> query(ShopItem shopItem) {
        LambdaQueryWrapper<ShopItem> queryWrapper =
            new LambdaQueryWrapper<>(shopItem);
        return shopItemMapper.selectList(queryWrapper);
    }

    public Integer delete(Integer id) {
        return shopItemMapper.deleteById(id);
    }

    public Integer save(ShopItem shopItem) {
        if (Objects.nonNull(shopItem) && Objects.nonNull(shopItem.getId())) {
            return shopItemMapper.updateById(shopItem);
        } else {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            return shopItemMapper.insert(shopItem);
        }
    }
}
